Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow use of OpenSCAP result files in task xccdf_result_to_oscal_ar #1411

Merged
merged 2 commits into from
Dec 11, 2023

Conversation

Mab879
Copy link
Contributor

@Mab879 Mab879 commented Jun 27, 2023

Types of changes

  • Hot fix (emergency fix and release)
  • Bug fix (non-breaking change which fixes an issue)
  • [x ] New feature (non-breaking change which adds functionality)
  • Documentation (change which affects the documentation site)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Release (develop -> main)

Quality assurance (all should be covered).

  • My code follows the code style of this project.
  • Documentation for my change is up to date?
  • My PR meets testing requirements.
  • All new and existing tests passed.
  • All commits are signed-off.

Summary

Before this commit if you wanted to use result files from OpenSCAP in the task xccdf_result_to_oscal_ar you had to extract the TestResult element and place it as the root of the XML document, otherwise the resulting OSCAL document would be blank. Thus making it impossible to directly use output from OpenSCAP with the task.

With this commit the task will detect that the root element is not TestResult and then it will find the TestResult element in the XML document. This allows the use of files created by OpenSCAP using the --results and --results-arf switches.

Fixes #1410

Key links:

Before you merge

  • Ensure it is a 'squash commit' if not a release.
  • Ensure CI is currently passing
  • Check sonar. If you are working for a fork a maintainer will reach out, if required.

@degenaro degenaro changed the title feat: Allow use of OpenSCAP result files in task xccdf_result_to_oscal_ar feat: allow use of OpenSCAP result files in task xccdf_result_to_oscal_ar Jun 28, 2023
Copy link
Collaborator

@degenaro degenaro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this submission!

  1. Are other namespaces possible? If so should there be a list used until the right one is found?
  2. Alternatively, should the trestle task xccdf-result-to-oscal-ar be enhanced to accept an optional config flag, perhaps namespace = http://checklists.nist.gov/xccdf/1.2?
  3. Can you add a test case to tests/trestle/tasks/xccdf_result_to_oscal_ar_test.py?

@Mab879
Copy link
Contributor Author

Mab879 commented Jun 30, 2023

1. Are other namespaces possible? If so should there be a list used until the right one is found?

There might be one more, I can add that to the task logic.

2. Alternatively, should the `trestle task xccdf-result-to-oscal-ar` be enhanced to accept an optional config flag, perhaps `namespace = http://checklists.nist.gov/xccdf/1.2`?

I think searching for the correct namespace might be best option.

3. Can you add a test case to `tests/trestle/tasks/xccdf_result_to_oscal_ar_test.py`?

Done. The test files are rather large, I welcome suggestions on this.

@degenaro
Copy link
Collaborator

With respect to the code: is http://checklists.nist.gov/xccdf/1.2 the only possibility or are there other common versions that should be checked if 1.2 is not the correct one (e.g. 1.1, 1.3, 2.0...)?

With respect to the test cases, please consider: it would seem that only 1 new test case and 1 corresponding data file are needed to cover the new code, and the test data file should be reduced (hacked, if you will) to the bare minimum amount needed to perform the new ns test.

Thx!

@degenaro
Copy link
Collaborator

Do you wish to continue with this PR? Another release of trestle is imminent, then the direction will be toward upgrading to the current version of OSCAL.

Also, the value for ns should not be hardcoded? Nor should the search term .//checklist12:TestResult ?

@Mab879
Copy link
Contributor Author

Mab879 commented Nov 17, 2023

This is something that I'm still interested in working on.

The ns value is the XML namespace mapping and checklist12:TestResult is just using those XML namespaces.

@degenaro
Copy link
Collaborator

This is something that I'm still interested in working on.

The ns value is the XML namespace mapping and checklist12:TestResult is just using those XML namespaces.

But it is bad practice to hardocde values in code that are not typically universal, no?

@Mab879
Copy link
Contributor Author

Mab879 commented Nov 30, 2023

This is something that I'm still interested in working on.
The ns value is the XML namespace mapping and checklist12:TestResult is just using those XML namespaces.

But it is bad practice to hardocde values in code that are not typically universal, no?

So the ns values are from the standards so the should be universal.

@Mab879 Mab879 marked this pull request as ready for review November 30, 2023 23:28
@degenaro
Copy link
Collaborator

degenaro commented Dec 5, 2023

Please try running:

make code-format
make code-lint

@degenaro
Copy link
Collaborator

degenaro commented Dec 7, 2023

We are close to making a release in the next few days. If you can run the make commands above and deliver the revised formatted code, I can approve, then you can merge. Otherwise there will be a freeze on new features until after upgrading to new version of OSCAL 1.1.2. Thx!

@degenaro
Copy link
Collaborator

degenaro commented Dec 7, 2023

tests/trestle/tasks/xccdf_result_to_oscal_ar_test.py:449:1: D103 Missing docstring in public function
tests/trestle/tasks/xccdf_result_to_oscal_ar_test.py:470:1: D103 Missing docstring in public function

@Mab879
Copy link
Contributor Author

Mab879 commented Dec 7, 2023

tests/trestle/tasks/xccdf_result_to_oscal_ar_test.py:449:1: D103 Missing docstring in public function tests/trestle/tasks/xccdf_result_to_oscal_ar_test.py:470:1: D103 Missing docstring in public function

Thanks for the output. I have struggling to get make code-lint to run locally.

@degenaro
Copy link
Collaborator

degenaro commented Dec 7, 2023

Here is the trick:

  1. python -m venv venv.trestle
  2. source venv.trestle/bin/activate
  3. cd compliance-trestle
  4. make install
  5. make develop
  6. make code-format
  7. make code-lint

@degenaro degenaro self-requested a review December 7, 2023 20:53
Copy link
Collaborator

@degenaro degenaro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Please:

  1. Update Branch (out of sync)
  2. Squash and Merge

…l_ar

Before this commit if you wanted to use result files from OpenSCAP
in the task xccdf_result_to_oscal_ar you had to extract the
`TestResult` element and place it as the root of the XML
document, otherwise the resulting OSCAL document would be
blank. Thus making it impossible to directly use output from
OpenSCAP with the task.

With this commit the task will detect that the root element
is not `TestResult` and then it will find the `TestResult`
element in the XML document. This allows the use of files
created by OpenSCAP using the `--results` and `--results-arf`
switches.

Signed-off-by: Matthew Burket <[email protected]>
@Mab879
Copy link
Contributor Author

Mab879 commented Dec 7, 2023

LGTM.

Please:

1. Update Branch (out of sync)

2. Squash and Merge

Done. Looks like I will need approval again for the CI to run.

@degenaro
Copy link
Collaborator

I think you should be able to squash and merge now...?

@Mab879
Copy link
Contributor Author

Mab879 commented Dec 11, 2023

I think you should be able to squash and merge now...?

I'm still seeing "Only those with write access to this repository can merge pull requests."

@degenaro degenaro merged commit eeb715c into oscal-compass:develop Dec 11, 2023
16 checks passed
@degenaro
Copy link
Collaborator

Ugh. I did the squash and merge, no worries. Thanks for this contribution!

@Mab879 Mab879 deleted the openscap_ar branch December 11, 2023 16:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow the use of OpenSCAP files in task xccdf-result-to-oscal-ar
2 participants